[LIBXC] Refactor xc_domain_resume() into its own source file.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Fri, 19 Jan 2007 18:32:28 +0000 (18:32 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Fri, 19 Jan 2007 18:32:28 +0000 (18:32 +0000)
The idea is that this file is where we will have two implementations
of 'suspend cancellation': one which the guest is aware of (and is
faster) and the other which does more work to avoid requiring guest
modifications.

Signed-off-by: Keir Fraser <keir@xensource.com>
tools/libxc/Makefile
tools/libxc/xc_domain.c
tools/libxc/xc_resume.c [new file with mode: 0644]
tools/libxc/xenctrl.h

index 8a563d00e081097d80e06a8d34508ae77de16ddd..03dae2992ef68a1ed30aec30c603d02d7bd422d4 100644 (file)
@@ -15,6 +15,7 @@ CTRL_SRCS-y       += xc_private.c
 CTRL_SRCS-y       += xc_sedf.c
 CTRL_SRCS-y       += xc_csched.c
 CTRL_SRCS-y       += xc_tbuf.c
+CTRL_SRCS-y       += xc_resume.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
 CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c
 CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
index 995b877ac02f27357ace117febe3df4f796098c8..4b9c5ea70d16aecfccdfd4da1397243d61634a73 100644 (file)
@@ -89,16 +89,6 @@ int xc_domain_shutdown(int xc_handle,
 }
 
 
-int xc_domain_resume(int xc_handle,
-                      uint32_t domid)
-{
-    DECLARE_DOMCTL;
-    domctl.cmd = XEN_DOMCTL_resumedomain;
-    domctl.domain = (domid_t)domid;
-    return do_domctl(xc_handle, &domctl);
-}
-
-
 int xc_vcpu_setaffinity(int xc_handle,
                         uint32_t domid,
                         int vcpu,
@@ -293,9 +283,9 @@ int xc_domain_hvm_setcontext(int xc_handle,
 }
 
 int xc_vcpu_getcontext(int xc_handle,
-                               uint32_t domid,
-                               uint32_t vcpu,
-                               vcpu_guest_context_t *ctxt)
+                       uint32_t domid,
+                       uint32_t vcpu,
+                       vcpu_guest_context_t *ctxt)
 {
     int rc;
     DECLARE_DOMCTL;
@@ -611,7 +601,6 @@ int xc_vcpu_setcontext(int xc_handle,
         unlock_pages(ctxt, sizeof(*ctxt));
 
     return rc;
-
 }
 
 int xc_domain_irq_permission(int xc_handle,
diff --git a/tools/libxc/xc_resume.c b/tools/libxc/xc_resume.c
new file mode 100644 (file)
index 0000000..ea9e121
--- /dev/null
@@ -0,0 +1,35 @@
+#include "xc_private.h"
+
+/*
+ * Resume execution of a domain after suspend shutdown.
+ * This can happen in one of two ways:
+ *  1. Resume with special return code.
+ *  2. Reset guest environment so it believes it is resumed in a new
+ *     domain context.
+ * (2) should be used only for guests which cannot handle the special
+ * new return code. (1) is always safe (but slower).
+ * 
+ * XXX Only (2) is implemented below. We need to use (1) by default!
+ */
+int xc_domain_resume(int xc_handle, uint32_t domid)
+{
+    vcpu_guest_context_t ctxt;
+    DECLARE_DOMCTL;
+    int rc;
+
+    /*
+     * Set hypercall return code to indicate that suspend is cancelled
+     * (rather than resuming in a new domain context).
+     */
+#if defined(__i386__) || defined(__x86_64__)
+    if ( (rc = xc_vcpu_getcontext(xc_handle, domid, 0, &ctxt)) != 0 )
+        return rc;
+    ctxt.user_regs.eax = 1;
+    if ( (rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt)) != 0 )
+        return rc;
+#endif
+
+    domctl.cmd = XEN_DOMCTL_resumedomain;
+    domctl.domain = domid;
+    return do_domctl(xc_handle, &domctl);
+}
index 37d12d5788544765a195cd77e8f62de38fa29d61..9c175e187cd7d703c4c019598e08579b79e2718a 100644 (file)
@@ -360,9 +360,9 @@ int xc_domain_hvm_setcontext(int xc_handle,
  * @return 0 on success, -1 on failure
  */
 int xc_vcpu_getcontext(int xc_handle,
-                               uint32_t domid,
-                               uint32_t vcpu,
-                               vcpu_guest_context_t *ctxt);
+                       uint32_t domid,
+                       uint32_t vcpu,
+                       vcpu_guest_context_t *ctxt);
 
 typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t;
 int xc_vcpu_getinfo(int xc_handle,